const express = require("express")
const app = express();
const path = require("path");

//处理body请求体的中间件
app.use(express.urlencoded())
app.use(express.json())

app.post('/adduser', (req, res) => {
    const {
        name,
        age,
        sex
    } = req.body

    if (!name || !age || !sex) {
        return res.send({
            code: 10001,
            mes: "添加失败",
            data: null
        })
    }

    res.send({
        code: 10000,
        mes: "添加成功",
        data: null
    })
})


// 静态资源
app.get('/1', (req, res) => {
    const filepath = path.resolve(__dirname, "./post请求练习.html")
    res.sendFile(filepath)
})

app.listen(3000, () => {
    console.log('服务器启动成功');
})